package com.hanamaki.dataStructDemo;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class LinkedListTest {

    public static void main(String[] args) {
        List<String> list = new LinkedList<>();
        list.add("second");
        // 向下标为0的位置下添加元素
        ((LinkedList) list).addFirst("first");
        list.add(0, "1");
        System.out.println(list);

        // 获取下标为0 的
        System.out.println(list.get(0));

        // 遍历
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

        for (String s : list) {
            System.out.println(s);
        }

        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }

}
